// index.js
import Car from './Car';

const car = new Car();
car.hooks.calculateRoutes.tapPromise('calculateRoutesPlugin1', (result) => {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            console.log('计算路线1', result);

            resolve(1);
        }, 1000);
    });
});

car.hooks.calculateRoutes.tapPromise('calculateRoutesPlugin2', (result) => {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            console.log('计算路线2', result);
            resolve(2);
        }, 2000);
    });
});

car.calculateRoutes().then(() => { console.log('最终的回调'); });
// 1s过后，打印计算路线1 undefined，再过2s打印计算路线2 1，然后立马打印最终的回调。


// car.drift((result) => { console.log('final callback', result); });
// Expected result: 2nd drift, final callback, 1st drift
// Actual result:  2st drift, 1st drift, final callback. It didn't bail.


// index.js
// const car = new Car()
// car.hooks.calculateRoutes2.tapAsync('calRoutesPlugin1', (callback) => {
//  setTimeout(() => {
//  console.log('计算路线1', callback)
//  callback(1)
//  }, 3000)
// })
// car.hooks.calculateRoutes2.tapAsync('calRoutesPlugin2', (callback) => {
//  setTimeout(() => {
//  console.log('计算路线2')
//  callback(2)
//  }, 1000)
// })
// car.calculateRoutes2((res) => { console.log('最终的回调, res: ', res) })

// car.hooks.drift2.tapAsync('driftPlugin1', (callback) => {
//   setTimeout(() => {
//   console.log('漂移1', callback)
//   callback(false,2)
//   }, 3000)
//  })
//  car.hooks.drift2.tapAsync('driftPlugin2', (callback) => {
//   setTimeout(() => {
//   console.log('漂移2')
//   callback(0, 2)
//   }, 1000)
//  })
//  car.drift2((res) => { console.log('最终的回调, res: ', res) })